package com.pucong.gitee.database.backup.common.selfenum;

import com.fasterxml.jackson.annotation.JsonCreator;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel("redis 数据类型 枚举类")
public enum RedisDataType implements CommonEnum<Integer> {
    无(0, "无"),
    set(1, "set"),
    zset(2, "zset"),
    list(3, "list"),
    hash(4, "hash"),
    str(5, "str");

    @ApiModelProperty(value = "key",example = "0")
    private Integer key;

    @ApiModelProperty("描述")
    private String desc;

    RedisDataType(Integer key, String desc) {
        this.key = key;
        this.desc = desc;
    }

    @Override
    public Integer getValue() {
        return this.key;
    }

    @Override
    public String getName() {
        return this.name();
    }

    @JsonCreator
    public static RedisDataType findEnumByValue(Integer value){
        for (RedisDataType item : RedisDataType.values()) {
            if (item.getValue().equals(value)) {
                return item;
            }
        }
        return null;
    }

    public static RedisDataType findEnumByName(String name){
        for (RedisDataType item : RedisDataType.values()) {
            if (item.getName().equals(name)) {
                return item;
            }
        }
        return null;
    }
}